from kivy.logger import Logger
from kivy.metrics import dp, sp
from kivy.uix.scrollview import ScrollView

from dryfire.layout.buttonLogLayout import ButtonLogLayout


class ButtonLogView(ScrollView):
    """
    """
    def __init__(self, on_press_handler, minimum_child_height, scroll_with_add, **kargs):
        kargs['do_scroll_x'] = False
        ScrollView.__init__(self, **kargs)
        # create logger layout
        self._layout = ButtonLogLayout(on_press_handler,
                                       minimum_child_height,
                                       scroll_with_add,
                                       size_hint=(1.0, None),
                                       spacing=dp(2),
                                       padding=dp(5))
        self.add_widget(self._layout)
        
    # view model methods

    def vm_log(self, text):
        """Add text onto the end of the log.
        Returns true if text was added else false.
        """
        return self._layout.log(text)
        
    def vm_clear_log(self):
        self._layout.clear_log()

